#include "espUtils.h"

void Serial_Init(unsigned long baud) {
    Serial.println();
    Serial.println();
    Serial.println();
    Serial.begin(baud);
    while (!Serial);      //  等待端口的释放
    Serial.printf("\nConnecting to WIFI...\n");
    for (uint8_t t = 4; t > 0; t--) {
        Serial.printf("[SETUP] WAIT %d...\n", t);
        Serial.flush();
        delay(1000);
    }

}
void WaitWiFi_Connect() {
    while (WiFiMulti.run() != WL_CONNECTED) {       // 如果WiFi没有连接，一直循环打印点
        delay(500);
        Serial.print(".");
    }
    Serial.println("\nConnected to network");
    Serial.print("My IP address is: ");
    Serial.println(WiFi.localIP());     // 打印开发板的IP地址

}


Ticker delayTimer;
/**
 * 延时N秒
 */
void delayNs(uint8_t m) {
    for(uint8_t index = 0; index<m; index ++) {
        delay(1000);
        ESP.wdtFeed();
    }
}
/*
 * 延时重启
*/
void delayRestart(float t) {
    Serial.print("Restart after ");
    Serial.print(t);
    Serial.println("s");
    delayTimer.attach(t, []() {
        Serial.println("\r\nRestart now!");
        ESP.restart();
    });
}
